<template>
  <div
    class="live-two-three-col-wrap"
    :class="{ three: isThree, mr: (index + 1) % 3 === 0 }"
    @click="toNext"
  >
    <div
      v-lazy:background-image="liveBgImage"
      class="img-box"
      :class="{ three: isThree }"
    >
      <div class="live-status" :class="{ three: isThree }">
        <!-- 10预告,20直播中, 大于20为结束或者回放 -->
        <div>
          <div
            v-if="liveObj.liveStatus === 10"
            class="forcast"
            :class="{ three: isThree }"
          >
            预告
          </div>
          <div
            v-else-if="liveObj.liveStatus === 20"
            class="living"
            :class="{ three: isThree }"
          >
            <explaining></explaining>
            <span>直播中</span>
          </div>
          <div
            v-else-if="liveObj.liveStatus !== 10 && liveObj.liveStatus !== 20"
            class="review"
            :class="{ three: isThree }"
          >
            回看
          </div>
        </div>
        <div
          v-if="liveObj.liveStatus === 10"
          class="right"
          :class="{ three: isThree }"
        >
          {{ liveObj.planBeginTime | filterLiveTime }}
        </div>
        <div v-else class="right" :class="{ three: isThree }">
          {{ liveObj.totalViewingCount | filterNum }}观看
        </div>
      </div>
      <like-animation
        v-if="liveObj.liveStatus !== 10"
        :count="liveObj.awesomeCount"
        class="animation__wrap"
        :class="{ three: isThree }"
      ></like-animation>
    </div>
    <p class="desc" :class="{ three: isThree }">{{ liveObj.liveTitle }}</p>
  </div>
</template>

<script>
import { LikeAnimation, Explaining } from '@akc/live-h5-sdk';
import { formatImgUrl } from '@/utils/util';

export default {
  name: 'liveMultiCol',
  components: {
    explaining: Explaining,
    LikeAnimation
  },
  filters: {
    filterNum(num) {
      if (num > 9999) {
        return `${Number((num / 10000).toFixed(2))}万`;
      }
      return num;
    }
  },
  props: {
    liveObj: {
      type: Object,
      default: () => {}
    },
    showType: {
      type: Number,
      default: 2
    },
    index: {
      type: Number,
      default: 0
    }
  },
  computed: {
    liveBgImage() {
      return formatImgUrl(this.liveObj.coverUrl, 200, 200);
    },
    isThree() {
      return this.showType === 3;
    }
  },
  methods: {
    toNext() {
      this.$emit('onToNext');
    }
  }
};
</script>

<style lang="scss" scoped>
.live-two-three-col-wrap {
  width: 174px;
  height: 214px;
  border-radius: 10px;
  overflow: hidden;
  background-color: #fff;
  margin-top: 10px;
  &.three {
    width: 114px;
    height: 142px;
    border-radius: 7px;
    margin-right: 6px;
  }
  &:last-child {
    margin-right: 0;
  }
  &.mr {
    margin-right: 0;
  }
  .img-box {
    width: 174px;
    height: 174px;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    position: relative;
    &.three {
      width: 114px;
      height: 114px;
    }
  }
  .live-status {
    position: absolute;
    left: 10px;
    top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;
    &.three {
      left: 4px;
      top: 6px;
    }
    .living {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 54px;
      height: 16px;
      background: linear-gradient(
        90deg,
        rgba(255, 70, 86, 1) 0%,
        rgba(255, 16, 16, 1) 100%
      );
      border-radius: 88px 0 0 88px;

      &.three {
        width: 47px;
        height: 14px;
      }
    }
    .review {
      width: 32px;
      height: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: linear-gradient(
        90deg,
        rgba(165, 18, 255, 1) 0%,
        rgba(104, 18, 255, 1) 100%
      );
      border-radius: 88px 0 0 88px;

      &.three {
        height: 14px;
      }
    }
    .forcast {
      width: 32px;
      height: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: linear-gradient(
        90deg,
        rgba(253, 132, 49, 1) 0%,
        rgba(255, 60, 0, 1) 100%
      );
      border-radius: 8px 0 0 8px;
      &.three {
        height: 14px;
      }
    }
    .right {
      padding: 0 6px;
      height: 16px;
      background: rgba(0, 0, 0, 1);
      border-radius: 0 8px 8px 0;
      opacity: 0.3;
      display: flex;
      align-items: center;
      font-size: 10px;
      font-family: PingFangSC-Regular;
      color: rgba(255, 255, 255, 1);
      box-sizing: border-box;
      &.three {
        height: 14px;
      }
    }
  }
  .animation__wrap {
    position: absolute;
    right: 0;
    bottom: 7px;
    &.three {
      bottom: 2px;
    }
  }
  .desc {
    width: 154px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 10px auto;
    font-size: 14px;
    font-family: PingFangSC-Regular;
    color: rgba(51, 51, 51, 1);
    &.three {
      width: 102px;
      margin: 6px auto;
    }
  }
}
</style>
